package com.zzyl.controller;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingElderDto;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目相关接口")
public class NursingProjectController extends BaseController {

    @Autowired
    private NursingProjectService nursingProjectService;

    @GetMapping
    @ApiOperation("分页条件查询护理项目")
    public ResponseResult getProjectList(@ApiParam(value = "护理项目名称") String name, Integer status, Integer pageNum, Integer pageSize) {
        PageResponse<NursingProjectVo> pageResponse = nursingProjectService.selectByPage(name, status, pageNum, pageSize);
        return success(pageResponse);
    }

    /**
     * 添加护理项目
     *
     * @param nursingProjectDto 护理项目数据传输对象
     * @return 操作结果
     */
    @ApiOperation(value = "添加护理项目", notes = "根据传入的护理项目数据传输对象创建新的护理项目")
    @PostMapping
    public ResponseResult addProject(
            @ApiParam(value = "护理项目数据传输对象", required = true)
            @RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.addProject(nursingProjectDto);
        return success(success().getOperationTime());
    }


    @ApiOperation(value = "根据id查询护理项目", notes = "根据id查询护理项目")
    @GetMapping("/{id}")
    public ResponseResult getProjectById(
            @ApiParam(value = "护理项目id", required = true)
            @PathVariable("id") Long id) {
        NursingProjectVo nursingProjectVo = nursingProjectService.selectById(id);
        return success(nursingProjectVo);
    }

    @ApiOperation(value = "修改护理项目", notes = "根据传入的护理项目数据传输对象修改护理项目")
    @PutMapping
    public ResponseResult updateProject(
            @ApiParam(value = "护理项目数据传输对象", required = true)
            @RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.updateProject(nursingProjectDto);
        return success(success().getOperationTime());
    }
}